package com.qiyeweixin.Page;

import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.WebElement;

/**
 * 日程界面
 */
public class SchedulePage extends BasePage{

    private final String[] ButtonAddNew = {"//*[contains(@text, '新建日程')]", "新建日程编辑框"};
    private final String[] InputTheme = {"//*[contains(@text, '活动主题')]", "活动主题输入框"};
    private final String[] ButtonAllDay = {"//*[@resource-id='com.tencent.wework:id/icx']", "点选按钮"};
    private final String[] ButtonSave = {"//*[contains(@text, '保存')]", "保存按钮"};
    private final String[] ButtonNewTitle = {"//*[@resource-id='com.tencent.wework:id/i_w']", "日程标题"};

    public SchedulePage(AndroidDriver androidDriver) {
        super(androidDriver);
    }

    /**
     * 添加日程
     * @param scheduleDesc 需要添加的会议主题名称
     *         点击新建日程编辑框
     *         输入会议主题
     *         打开全天点选按钮
     *         打开音视频会议单选按钮
     *         点击保存
     * @return 返回page本身
     */
    public SchedulePage addNewSchedule(String scheduleDesc){
        click(ButtonAddNew)
                .sendKeys(InputTheme, scheduleDesc)
                .clicks(ButtonAllDay, 0)
                .clicks(ButtonAllDay, 1)
                .click(ButtonSave);
        return this;
    }

    /**
     * 获取日程信息用于断言
     * @return 返回主题名称数组
     */
    public String[] getScheduleInfo(){
        return finds(ButtonNewTitle).stream().map(WebElement::getText).toArray(String[]::new);
    }
}
